//
//  DateDisplayView.swift
//  ios
//
//  Created by zhuxietong on 2017/2/28.
//  Copyright © 2017年 zhuxietong. All rights reserved.
//

import UIKit
import Eelay

open class DayView: RuleCell {
    public let titleL = UILabel()
    
    override open func addLayoutRules() {
        let infoL = UILabel()
        contentView.eelay = [
            [titleL,[ee.X.Y,[0,-6]]],
            [infoL,[titleL,ee.B,ee.T],[ee.X]],
        ]
        self.contentView.backgroundColor = .white
        _ = titleL.ui.color(hex: "#ca191d").center.bfont19
        _ = infoL.ui.color(hex: "#888").center.bfont13.text("点击此处确认".loc)
        
        contentView.bsui.set(radius: 28, width: 0, color: nil)
        
    }
    
    override open func mo_model_reload() {

        let date = DataNode.path(node: "value", mo.model, value: Date())
        titleL.text = date["MM月dd日".loc]
    }
}

open class DayView1: RuleCell {
    public let titleL = UILabel()
    
    override open func addLayoutRules() {
        let infoL = UILabel()
        contentView.eelay = [
            [titleL,[ee.X.Y,[0,-6]]],
            [infoL,[titleL,ee.B,ee.T],[ee.X]],
        ]
        self.contentView.backgroundColor = .white
        _ = titleL.ui.color(hex: "#ca191d").center.bfont19
        _ = infoL.ui.color(hex: "#888").center.bfont13.text("点击此处确认".loc)
        
        contentView.bsui.set(radius: 28, width: 0, color: nil)
        
    }
    
    override open func mo_model_reload() {

        let date = DataNode.path(node: "value", mo.model, value: Date())
        titleL.text = date["YYYY年MM月dd日".loc]
    }
}

open class EeDateEventsView: JoView {
    public typealias Kit = RuleCell
    public let placeHolderL = UILabel()

    open var events:[NSMutableDictionary] = [NSMutableDictionary]()
    public var confirmDate:(NSMutableDictionary)->Void = {_ in}
    public var datesView = RuleView<Kit>()


}

open class DatesDisplayView: EeDateEventsView {
    typealias Kit = DayView
    public var name:String = ""
    override open var events:[NSMutableDictionary]{
        get{
            return super.events
        }
        set{
            super.events = newValue
            if newValue.count > 0
            {
                let model = ["options":newValue].mutable_dictionary
                datesView.mo.model = model
            }
            
        }

    }
    
    
    override open func addLayoutRules() {
        
        datesView.limit_width = Swidth * 0.5
        datesView.item_height = 56
        eelay = [
            [placeHolderL,[ee.X.Y]],
            [datesView,[ee.X.Y]]
        ]
        
        placeHolderL.ui.center.cl_fff.bfont19.text("请选择时间".loc)
        weak var wself = self
        datesView.touchAction = {
            cell,ID,model in
            wself?.confirmDate(model)
        }
    }
    

//    func touch(ruleView: UIView, cell: RuleCell, actionID: String, model: NSMutableDictionary) {
//        self.confirmDate(model)
//    }
//    func touch(ruleView: UIView, cell: RuleCell, index: Int, model: NSMutableDictionary) {
//        self.confirmDate(model)
//    }
    
}

open class DatesDisplayView1: EeDateEventsView {
    
    public var name:String = ""
    override open var events:[NSMutableDictionary]{
        get{
            return super.events
        }
        set{
            super.events = newValue
            if newValue.count > 0
            {
                let model = ["options":newValue].mutable_dictionary
                datesView.mo.model = model
            }
            
        }
        
    }
    override open func addLayoutRules() {
        
        datesView.limit_width = Swidth * 0.5
        datesView.item_height = 56
        eelay = [
            [placeHolderL,[ee.X.Y]],
            [datesView,[ee.X.Y]]
        ]
        
        weak var wself = self
        datesView.touchAction = {
            cell,ID,model in
            wself?.confirmDate(model)
        }
        placeHolderL.ui.center.cl_fff.bfont19.text("请选择时间".loc)
    }
    
//    func touch(ruleView: UIView, cell: RuleCell, actionID: String, model: NSMutableDictionary) {
//        self.confirmDate(model)
//    }
//    
//    func touch(ruleView: UIView, cell: RuleCell, index: Int, model: NSMutableDictionary) {
//        self.confirmDate(model)
//    }
    
}

